package algorithm_optimal_solution.LinkedList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//单链表删除倒数第K个节点：链表从头走到尾，每走一步K-1。然后判断K>0时不调整链表；K==0时删除链表第一位；K<0时链表再从头走到尾，每走一步K+1，
// 当K==0时的那一位就是要删除的前一位。
public class RemoveFloatLinkedListBackNode {

    static class Node{
        private int value;
        private Node node;

        public Node(int value,Node node){
            this.value = value;
            this.node = node;
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        public Node getNode() {
            return node;
        }

        public void setNode(Node node){
            this.node = node;
        }
    }

    public void removeOneLinkedListBackIndex(Node head,int backIndex){
        Node currentNode = head;
        while(currentNode != null){
            backIndex--;
            currentNode = currentNode.getNode();
        }
        int newIndex = backIndex;
        StringBuilder sb = new StringBuilder();
        while(head != null){
            if(backIndex == 0){
                head = head.getNode();
                backIndex++;
            }else if(backIndex < 0){
                newIndex++;
                if(newIndex == 0){
                    head.setNode(head.getNode().getNode());
                }
            }
            sb.append(head.getValue()).append(" ");
            head = head.getNode();
        }
        System.out.print(sb);
    }

    public static void main(String[] args)throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        String[] values = scanner.readLine().split(" ");
        int len = Integer.parseInt(values[0]);
        int backIndex = Integer.parseInt(values[1]);
        String[] numbers = scanner.readLine().split(" ");
        Node node = null;
        for(int i = len - 1;i >= 0;i--){
            node = new Node(Integer.parseInt(numbers[i]),node);
        }
        new RemoveFloatLinkedListBackNode().removeOneLinkedListBackIndex(node,backIndex);
    }
}
